package demo1;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: wx
 * Date: 2023-09-13
 * Time: 1:49
 */
public class CardDemo {

    private final String[] suit = {"♠", "♥", "♣", "♦"};
    /**
     * 52 1_k
     *  j   q  k
     *  11 12 13
     * @return
     */

    public List<Card> buyCard () {
        List<Card> cardList = new ArrayList<>();

        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <=13 ; j++) {
                Card card = new Card(suit[i],j);
                cardList.add(card);
            }
        }
        return cardList;
    }
    public void shuffle (List<Card> cardList) {
        Random random = new Random();



        for(int i = cardList.size();i>0;i--) {
            int index = random.nextInt();
            swap(cardList,i,index);
        }
    }
    private void swap(List<Card> cardList, int a,int b) {
        Card tmp = cardList.get(a);
        cardList.set(a,tmp);
        cardList.set(a,cardList.get(b));
    }
    /**
     * 三个人没个人轮流揭牌五张
     * @param cardList
     */
    public void getCard(List<Card> cardList) {

        List<Card> hands1 = new ArrayList<>();
        List<Card> hands2 = new ArrayList<>();
        List<Card> hands3 = new ArrayList<>();

        List<List<Card>> handss = new ArrayList<>();
        handss.add(hands1);
        handss.add(hands2);
        handss.add(hands3);
        for (int i = 0; i < 5; i++) {
            //j代表人
            for (int j = 0; j < 3; j++) {
                Card card = cardList.remove(0);
                handss.get(j).add(card);
            }
        }
        System.out.println("第1个人揭牌如下：");
        System.out.println(hands1);
        System.out.println("第2个人揭牌如下：");
        System.out.println(hands2);
        System.out.println("第3个人揭牌如下：");
        System.out.println(hands3);
    }
}


